import javax.sound.sampled.*;

public class SoundPlayer {
    private AudioFormat m_format;
    private SourceDataLine m_playSoundLine;
    int m_bufferSize;

    public SoundPlayer(AudioFormat format, int bufferSize)
    {
        m_format = format;
        m_bufferSize = bufferSize;

        DataLine.Info sourceInfo = new DataLine.Info(SourceDataLine.class, m_format);
        try
        {
            if (AudioSystem.isLineSupported(sourceInfo))
            {
                m_playSoundLine = (SourceDataLine)AudioSystem.getLine(sourceInfo);
                m_playSoundLine.open(m_format, m_bufferSize);
                m_playSoundLine.start();
            }
        }
        catch (LineUnavailableException e)
        {
            System.out.println("Line unavailable " + e);
            return;
        }
   }

   public void play(byte[] sound, int length)
   {

       m_playSoundLine.write(sound, 0, length);

   }

}
